const $api = require('../../utils/api.js').API;
Page({
    data: {
        current: 0,
        process: {},
        taker: {},
        publisher: {},
        orderDetail: {}
    },

    onLoad(e) {
        console.log(e)
        let orderDetail = JSON.parse(e.orderDetail)
        let publisher = JSON.parse(e.publisher)
        this.setData({
            orderDetail,
            publisher
        })
        this.getProcess(orderDetail._id)
        this.getTaker(orderDetail.taker)
    },

    // 获取交易流程
    getProcess(e) {
        $api.getProcess(e)
            .then(res => {
                console.log(res)
                this.setData({
                    process: res.data.data[0],
                })
            })
            .catch(err => {
                console.log(err)
            })
    },

    // 获取接单人信息
    getTaker(e) {
        $api.getUserinfo({ openid: e })
            .then(res => {
                this.setData({
                    taker: res.data.data[0]
                })
            })
            .catch(err => { console.log(err) })
    },

    // 去往投诉页
    toComplain() {
        wx.navigateTo({
            url: `/pages/complain/complain?order_id=${this.data.orderDetail._id}`,
        });
    }
});
